package Controllers;
import java.util.Hashtable;

import javax.swing.JOptionPane;

import Draw.IDraw;
import Factories.DrawBehaviourFactory;
import Views.VisualizationWindow;


public class DrawController {

	private IDraw iDraw;
	private VisualizationWindow window;
	private Hashtable<String,String> choices;
	private DrawBehaviourFactory behaviourFactory;
	
	public DrawController() {
		this.behaviourFactory = new DrawBehaviourFactory();
		this.window = new VisualizationWindow();
		this.choices = new Hashtable<String,String>();
		
		choices.put("Rectangle Aleatoire", "DrawRectangle");
	}
	
	public void go() {		
		iDraw = this.behaviourFactory.buildDrawBehaviour(choices.get(askBehaviour(choices)));
		window.addBehaviour(iDraw);
		window.setVisible(true);
	}
	
	/***
	 * Permet de choisir le mode de dessin
	 * @param table
	 * @return clef de la hashtable choisie par l'utilisateur
	 */
	private String askBehaviour(Hashtable<String, String> table) {
		String retour, possibilities[] = new String[table.size()];
		int j = 0;

		//Ajout des comportement de dessin dans la dropdown list
		for(String key : table.keySet()) { 
			possibilities[j] = key;
			j++;
		}
		
		retour = (String)JOptionPane.showInputDialog(
				null,
				"Choisir le comportement de dessin",
				"Mode de dessin",
				JOptionPane.PLAIN_MESSAGE,
				null,
				possibilities,
				"Rectangle Aleatoire");

		return retour;
	}

	public VisualizationWindow getWindow() {
		return window;
	}

	public void setWindow(VisualizationWindow window) {
		this.window = window;
	}
}
